/*
  <exp>  -> <term> { <addop> <term> }
  <addop> ->  + | -
  <term> -> <factor> { <mulop> <factor> }
  <mulop>  -> *
  <factor> -> {<expr>} | Number 
 */

#include <stdio.h>
#include <stdlib.h>

char token;

int express(void);
int term(void);
int factor(void);

void error(void)
{
  fprintf(stderr,"Error\n");
  exit(1);
}

void match(char expectedToken)
{
  if(token == expectedToken) token = getchar();
  else
    error();
}

int main()
{
  int result;
  token = getchar();
  result = express();

  if(token == '\n')
    printf("Result = %d\n",result);
  else
    error();
  
  return 0;
}


int express(void)
{
  int temp = term();
  while((token == '+')||(token == '-')) 
    {
      switch(token)
        {
        case '+':
          match('+');
          temp += term();
          break;

        case '-':
          match('-');
          temp -= term();
          break;
        }
    }
  return temp;
}

int term(void)
{
  int temp = factor();

  while(token == '*') 
    {
      match('*');
      temp *= factor();
    }
  return temp;
}

int factor(void)
{
  int temp;
  if (token == '(') 
    {
      match('(');
      temp = express();
      match(')');
    }
  else if(isdigit(token))
    {
      ungetc(token,stdin);
      scanf("%d",&temp);
      token = getchar();
    }
  else
    error();
  return temp;
}
